﻿namespace Sidvall.UI.Dialogs
{
    public class MessageContext
    {
        #region Public Members

        public string Title { get; set; }
        public string Message { get; set; }
        public bool AllowMultipleSelect { get; set; }
        public MessageType MessageType { get; set; }
        public MessageOptionCollection Answers { get; private set; }
        public MessageOptionCollection MessageOptions { get; private set; }

        #region AnswerIsYes

        public bool AnswerIsYes
        {
            get
            {
                return this.Answers.AnswerIsYes;
            }
        }

        #endregion

        #region Copy

        public MessageContext Copy()
        {
            MessageContext item;

            item = new MessageContext();
            item.Import(this);

            return item;
        }

        #endregion
        #region Import

        public void Import(MessageContext item)
        {
            if (item == null)
                throw new System.ArgumentNullException("item");

            this.Title = item.Title;
            this.Message = item.Message;
            this.AllowMultipleSelect = item.AllowMultipleSelect;
            this.MessageType = item.MessageType;
            this.Answers.Import(item.Answers);
            this.MessageOptions.Import(item.MessageOptions);
        }

        #endregion

        #endregion
        #region Factory Members

        #region NewMessageContext

        public static MessageContext NewMessageContext(string title, string message, MessageType messageType)
        {
            var item = new MessageContext(title, message, false, messageType);
            item.MessageOptions.AddOk(true, true);
            return item;
        }

        #endregion
        #region NewOkCancelMessageContext

        public static MessageContext NewOkCancelMessageContext(string title, string message, MessageType messageType, bool okIsDefault)
        {
            MessageContext item;

            item = new MessageContext(title, message, false, messageType);
            if (okIsDefault)
                item.MessageOptions.AddOkCancel(Sidvall.Resources.ResourceKeys.OkOptionId);
            else
                item.MessageOptions.AddOkCancel(Sidvall.Resources.ResourceKeys.CancelOptionId);

            return item;
        }

        #endregion
        #region NewYesNoMessageContext

        public static MessageContext NewYesNoMessageContext(string title, string message, MessageType messageType, bool yesIsDefault)
        {
            MessageContext item;

            item = new MessageContext(title, message, false, messageType);
            if (yesIsDefault)
                item.MessageOptions.AddYesNo(Sidvall.Resources.ResourceKeys.YesOptionId);
            else
                item.MessageOptions.AddYesNo(Sidvall.Resources.ResourceKeys.NoOptionId);

            return item;
        }

        #endregion
        #region NewYesNoCancelMessageContext

        public static MessageContext NewYesNoCancelMessageContext(string title, string message, MessageType messageType, bool yesIsDefault)
        {
            MessageContext item;

            item = new MessageContext(title, message, false, messageType);
            if (yesIsDefault)
                item.MessageOptions.AddYesNoCancel(Sidvall.Resources.ResourceKeys.YesOptionId);
            else
                item.MessageOptions.AddYesNoCancel(Sidvall.Resources.ResourceKeys.NoOptionId);

            return item;
        }

        #endregion

        #endregion
        #region Constructor

        private MessageContext()
        {
            this.MessageType = MessageType.Information;
            this.Answers = new MessageOptionCollection();
            this.MessageOptions = new MessageOptionCollection();
        }

        public MessageContext(string title, string message, bool allowMultipleSelect, MessageType messageType)
        {
            this.Title = title;
            this.Message = message;
            this.AllowMultipleSelect = allowMultipleSelect;
            this.MessageType = messageType;
            this.Answers = new MessageOptionCollection();
            this.MessageOptions = new MessageOptionCollection();
        }

        #endregion
    }
}
